/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.util.bdfparser.enums.cardeums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 枚举所有支持的卡片类型
 */
@Getter
@AllArgsConstructor
public enum CardTypeEnums {

    // 点
    POINT("POINT", PointCardEnums.values()),
    // 坐标系
    COORDINATE("COORDINATE", CoordinateCardEnums.values()),
    // 元素
    ELEMENT("ELEMENT", ElementCardEnums.values()),
    // 属性
    PROPERTY("PROPERTY", PropertyCardEnums.values()),
    // 材料
    MATERIAL("MATERIAL", MaterialCardEnums.values()),
    // 载荷
    LOAD("LOAD", LoadCardEnums.values()),;

    private final String type;

    private final CardName[] cardNames;

    // 检查是否支持的类型
    public static boolean isSupportedType(String cardType) {
        if (cardType == null || cardType.trim().isEmpty()) {
            return false;
        }
        return Arrays.stream(CardTypeEnums.values())
            .anyMatch(type -> type.getType().equalsIgnoreCase(cardType));
    }


    // 根据卡片名称获取对应的type
    public static String getCardTypeByName(String cardName) {
        if (cardName == null || cardName.trim().isEmpty()) {
            return null;
        }
        // Iterate over all card types and check if the card name exists in any of them
        for (CardTypeEnums cardTypeEnum : CardTypeEnums.values()) {
            for (CardName card : cardTypeEnum.getCardNames()) {
                if (card.getName().equalsIgnoreCase(cardName)) {
                    return cardTypeEnum.getType();
                }
            }
        }
        return null; // Return null if no matching card type is found
    }
}
